package com.design3.graduatethesissys.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.design3.graduatethesissys.common.utils.GetUserName;
import com.design3.graduatethesissys.domain.Subject;
import com.design3.graduatethesissys.service.impl.SubjectServiceImpl;
import com.design3.graduatethesissys.service.impl.XuantiServiceImpl;


@Controller
@RequestMapping(value = "/Student")
public class Xuanti {

	@Autowired
	XuantiServiceImpl xuantiService;
	@Autowired
	SubjectServiceImpl subjectService;
	
	@RequestMapping(value = "/Xuanti")
	public String demo(ModelMap pageSum){
		int SumItem = subjectService.searchCount();
		int SumPage = 0;
		if(SumItem < 10) {
			SumPage = 1;
		}else if(SumItem%10 == 0) {
			SumPage = SumItem/10;
		} else {
			SumPage = SumItem/10 + 1;
		}		
		pageSum.addAttribute("SumPage",SumPage);
		pageSum.addAttribute("SumItem",SumItem);
	    return "Student/Xuanti";
	}
	
	/**
	 * 
	 * @param sbj_id
	 * @param teh_id
	 * @return 成功返回success，失败返回false
	 */
	@RequestMapping(value = "/choose")
	@ResponseBody
	public String choose(@RequestParam("sbj_id") String sbj_id, @RequestParam("teh_id") String teh_id){
	    return xuantiService.xuanTi(sbj_id, teh_id);
	}
	
	/**
	 * 
	 * @param sbj_id
	 * @param teh_id
	 * @return 成功返回success，失败返回false
	 */
	@RequestMapping(value = "/choosePro")
	@ResponseBody
	public Subject choosePro(){
	    return xuantiService.searchSubjectByStuId(GetUserName.getUserName());
	}
}
